/***
 * @Description:
 * @Author: LI Yihong
 * @Email: liyh@jihua.ac.cn
 * @Date: 2024-10-23 17:37:58
 * @LastEditTime: 2024-10-23 17:37:58
 * @LastEditors: LI Yihong
 * @FilePath: \STM32F407_Board\applications\I2C\24C02.hpp
 */
#include "I2C.hpp"
#include "cxx_semaphore.h"

class EEPROM_24C02 : public I2C
{
public:
    using I2C::I2C;

    void run(void *parameter) override;

    bool init(const rt_uint8_t &addr);
    bool check();
    bool readByte(const rt_uint8_t &readAddr, rt_uint8_t &data);
    bool writeByte(const rt_uint8_t &writeAddr, const rt_uint8_t &data);
    bool read(const rt_uint8_t &readAddr, vector<rt_uint8_t> &data, const rt_uint32_t &numToRead);
    bool write(rt_uint8_t writeAddr, const vector<rt_uint8_t> &data);
    bool read(const rt_uint8_t &readAddr, string &str, const rt_uint32_t &numToRead);
    bool write(rt_uint8_t writeAddr, const string &str);

    shared_ptr<Semaphore> SemKey_0;
    shared_ptr<Semaphore> SemKey_1;

private:
    rt_uint16_t address; // address in i2c bus of 24C02

    static constexpr rt_uint8_t UNIV_ADDR = (0xA0 >> 1); // universal address of 24C02
    static constexpr rt_uint8_t MAX_MEM_ADDRESS = 255;   // max memory address of 24C02
};
